package com.lemon.exam.common.redis.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lemon.exam.common.redis.RedisService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * @author Lemon
 * @description 类对象
 * @since 2025/2/17 15:30
 */
@Slf4j
@Service
public class RedisServiceImpl implements RedisService {
    private final StringOperations stringOperations;
    private final HashOperations hashOperations;
    private final SetOperations setOperations;
    private final ListOperations listOperations;
    private final ZSetOperations zSetOperations;
    private final LockOperations lockOperations;
    private final IdOperations idOperations;

    public RedisServiceImpl(ReactiveRedisTemplate<String, Object> template, ObjectMapper objectMapper) {
        this.stringOperations = new StringOperations(objectMapper, template);
        this.hashOperations = new HashOperations(objectMapper, template);
        this.setOperations = new SetOperations(objectMapper, template);
        this.listOperations = new ListOperations(objectMapper, template);
        this.zSetOperations = new ZSetOperations(objectMapper, template);
        this.lockOperations = new LockOperations(objectMapper, template);
        this.idOperations = new IdOperations(objectMapper, template);
    }

    /**
     * 字符串操作
     *
     * @return
     */
    @Override
    public StringOperations string() {
        return stringOperations;
    }

    /**
     * Hash操作
     *
     * @return
     */
    @Override
    public HashOperations hash() {
        return hashOperations;
    }

    /**
     * Set操作
     *
     * @return
     */
    @Override
    public SetOperations set() {
        return setOperations;
    }

    /**
     * List操作
     *
     * @return
     */
    @Override
    public ListOperations list() {
        return listOperations;
    }

    /**
     * ZSet操作
     *
     * @return
     */
    @Override
    public ZSetOperations zset() {
        return zSetOperations;
    }

    /**
     * 锁操作
     *
     * @return
     */
    @Override
    public LockOperations lock() {
        return lockOperations;
    }

    /**
     * ID操作
     *
     * @return
     */
    @Override
    public IdOperations id() {
        return idOperations;
    }

}
